package cn.edu.scau.cmi.zengdefeng.Composite;

import java.util.Set;

public class ConsistentComposite  extends ConsistentComponent{
	
	public ConsistentComposite(ConsistentComponent parent,String name) {
		super(parent,name);
	}

	@Override
	public String toString() {
		return toString(1);
	}
	public String toString(int cent) {
		String parentName = getParent() == null ? "无" : getParent().getName();
		String blank = StringUtils.repeat("	", cent - 1);
		StringBuilder childrenList = new StringBuilder();
		for (ConsistentComponent organization : getChildren()) {
			String result = organization.toString(cent + 2);
			// 去掉换行符
			result = result.substring(0, result.length() - 1);
			// 加上逗号
			String string = result + "," + "\n";
			childrenList.append(string);
		}
		// 去掉最后一个逗号
		if (childrenList.length() >= 2) {
			childrenList.deleteCharAt(childrenList.length() - 2);
		}
		
		String string =  
				blank + "\"" + getName() + "\"" + ": " + "{" + "\n"
				+ blank + "	" + "\"" + "类型" + "\"" + ": " + "\"" + "团队" + "\"" + "," + "\n"
				+ blank + "	" + "\"" + "父亲" + "\"" + ": " + "\"" + parentName + "\"" + "," + "\n"
				+ blank + "	" + "\"" + "子节点" + "\"" + ": " + "[" + "\n"
				+ childrenList
				+ blank + "	" + "]" + "\n"
				+ blank + "}" + "\n";
		return string;
	}




}